<?php
class PLoader {
        const SUFFIX = '.class.php';
        public static function import($filePath,$base=null,$key='pisces') {
                static $paths;
                if(!isset($paths)) {
                        $paths = array();
                }
                $keysPath = $key?$filePath.$key:$filePath;

                if(!isset($paths[$keysPath])) {
                        $part = explode('.', $filePath);

                        $classname = ucfirst(array_pop($part));

                        if(!isset($base)) {
                                $base = dirname(__FILE__);
                        }

                        $path = str_replace('.',DS,$filePath);
                        //如果不是系统pisces文件夹下的类.则进行注册
                        self::register($classname,$base.DS.$path.self::SUFFIX);
                        $rs = include($base.DS.$path.self::SUFFIX);
                        $paths[$keysPath] = $rs;
                }
                return $paths[$keysPath];
        }

        public static function register($class = null,$path = null) {
                static $classes;
                if(!isset($classes)) {
                        $classes = array();
                }
                if($class && is_file($path)) {
                        $key = strtolower($class);
                        $classes[$key] = $path;
                        if(version_compare(phpversion(), '5.0')<0) {
                                self::loader($class);
                        }
                }
                return $classes;
        }
        /**
         * initLoder
         * 加载已缓存的类列表
         * 
         * @param array $classes
         */
        public static function initLoder($classes){
        	foreach($classes as $value){
        		include $value;
        	}
        }
        public static function loader($class) {
                $class = strtolower($class);

                if(class_exists($class)) return;
                //取得已经注册过的类
                $classes = self::register();
                //如果存在
                if(isset($classes[$class])) {
                        include_once "$classes[$class]";
                        return true;
                }
                return false;
        }
}
spl_autoload_register("SqmPengAutoload");
function SqmPengAutoload($class) {
        //引入已经注册过的类
        if(PLoader::loader($class)) {
                return true;
        }
        return false;
}
function pexit($message = 0) {
        exit($message);
}
?>
